import path from 'path'
import pkg from '../package.json'
import type { Encoding } from './types/common'
import type { HashAlgorithm } from './utils/hash'

// @ts-ignore
global['__env__'] = 'production'

const ENV = __env__

const isDev = ENV === 'development'

const configName = {
  send: ['fs.send.config.js', 'file-sail.send.config.js'],
  server: ['fs.server.config.js', 'file-sail.server.config.js']
}

const ignoreFile = '.sailignore'

const modulePath = path.resolve(__dirname, '../')

const config = {
  name: pkg.name,
  version: pkg.version,
  ENV,
  isDev,
  configName,
  /**
   * 缓存配置
   */
  cache: {
    names: {
      hashMap: 'hashMap.json',
      temp: 'temp',
      backup: 'backup',
      log: 'log'
    },
    hashMapEncoding: 'utf-8' as Encoding,
    hashMapSpace: 2,
    hashMapAlgorithm: 'md5' as HashAlgorithm
  },
  /**
   * 模块路径
   */
  modulePath,
  /**
   * 全局日志目录
   */
  globalLogDir: path.resolve(modulePath, 'log'),
  /**
   * 默认缓存目录
   */
  defaultCacheDir: path.resolve(modulePath, 'cache'),
  /**
   * 工作目录
   */
  cwd: process.cwd(),
  /**
   * 发送文件重试次数
   */
  sendFileRetryCount: 2,
  /**
   * 忽略文件
   */
  ignoreFile,
  /**
   * 文件分片大小
   */
  fileChunkSize: 128 * 1024,
  /**
   * 默认值
   */
  default: {
    port: 9000,
    /**
     * 缓存目录
     */
    cacheDir: '.sail',
    forceUseDefaultCachePath: false,
    backup: true,
    maxBackupCount: 3,
    sendIgnore: [...configName.send, ignoreFile]
  }
}

export default config
